/*const express = require('express') //引入express 模块
const app = express()              //创建实例
const router=require('./router')   //配置路由
const path = require('path');
app.use(express.static(path.join(__dirname, 'Photo')));
app.use(router)
app.listen(3000,()=>{
    console.log('Server running at http://127.0.0.1:3000/');
})*/
const express = require('express') //引入express 模块
const app = express()              //创建实例
const router=require('./router')   //配置路由
const path = require('path');
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.route('*').all((req, res, next) => {
    console.log(`${req.method}--${req.url}`)
    res.setHeader('Access-Control-Allow-Origin', "*")
    //跨域允许的header类型
    res.setHeader("Access-Control-Allow-Headers", "*")
    // 允许跨域携带cookie
    res.setHeader("Access-Control-Allow-Credentials", "true")
    // 允许的方法
    res.setHeader('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS')
    next()
})
app.use(express.static(path.join(__dirname, 'Photo')));
app.use(router)
app.listen(3000,()=>{
    console.log('Server running at http://127.0.0.1:3000/');
})
